package vmcs.controller;

import vmcs.boundary.SimulatorControlPanel;
import vmcs.utility.VMCSException;


// Copyright 1997 ISS.
// The contents contained in this document may not be reproduced in any
// form or by any means, without the written permission of ISS, other
// than for the purpose for which it has been supplied.
//
// Author: Olivo Miotto
//

public class SimulationController {

    private SimulatorControlPanel	scp = null;
    public  MainController              mCtrl = null;

    public SimulationController (MainController  ctrl) {
      mCtrl = ctrl;
      scp = new SimulatorControlPanel (this);
 //     scp.setSimulationActive (false);
    }

    public SimulatorControlPanel getSimulatorControlPanel () {
        //scp.setSimulationActive (false);
        return (scp);
    }

    public void displaySimulatorControlPanel () {
        scp.display();
    }

    public void stop () {
        mCtrl.closeDown ();
    }

    public void closeDown(){
      scp.closeDown();
    }



    public void start(){
     scp.setSimulationActive (true);
     scp.setActive(SimulatorControlPanel.BEGIN, false);
      //scp.setButtonState(SimulatorControlPanel.BEGIN, false);
    }

   // public void setButtonState(char id, boolean st){
   //   scp.setButtonState(id, st);
   // }

    public void setSimulationActive(boolean vl){
      scp.setSimulationActive(vl);
    }

    public void setupSimulator(){
      MaintenanceController    maintenanceCtrl;
      maintenanceCtrl = mCtrl.getMaintenanceController();
      StoreController          storeCtrl;

      storeCtrl = mCtrl.getStoreController();
      scp.setActive(SimulatorControlPanel.ACT_MACHINERY, false);
      //setButtonState(SimulatorControlPanel.ACT_MACHINERY, false);
      try {
          // activate when not login
          // always diaply the door locked; isOpen false
           storeCtrl.displayMachineryPanel();
           // display drink stock;
           storeCtrl.displayDrinkStock();
           // display coin quantity;
           storeCtrl.displayCoinStock();
          // storeCtrl.setDoorState(true);
          storeCtrl.displayDoorState();
        } catch (VMCSException e){
          System.out.println("SimulationController.setupSimulator:" + e);
        }
    }
      /**
       * set up customer panel
       * Needed to be filled in by student;
       */
      public void setupCustomer(){
    	  CustomerController   cctrl;
          cctrl = mCtrl.getCustomerController();
          scp.setActive(SimulatorControlPanel.ACT_CUSTOMER, false);
          cctrl.displayCustomerPanel();  
      }

      public void setupMaintainer(){
        MaintenanceController   mctrl;
        mctrl = mCtrl.getMaintenanceController();
        scp.setActive(SimulatorControlPanel.ACT_MAINTAINER, false);
        mctrl.displayMaintenancePanel();
    }

    public MainController  getMainController(){
      return mCtrl;
    }

}

